import adModel from "../../main/view/adView/adModel";
import { ZYEventMgr } from "../manager/YLEventMgr";
import wxAdRipoff from "./ad/wxAdRipoff";
import wxBanner from "./ad/wxBanner";
import wxCellBanner from "./ad/wxCellBanner";
import wxVideo from "./ad/wxVideo";
import { WXAPIMgr } from "./concrete/WXAPIManager";

/**
 * 广告管理入口
 * @author: xj.huang
 * @date: 2021/08/03 10:03:33
 */
class ADManager {
    /**广告管理 */
    /**视频管理 */
    voide = wxVideo;
    /**广告banner界面 */
    private _wxBannerMgr: wxBanner;
    /**广告cell */
    private _wxCellBanner: wxCellBanner;
    /**骗点 */
    private _wxAdRipoff: wxAdRipoff
    /**广告组件接口 */
    private _wxVideoAd: wxVideo;
    constructor() {
        // super()
    }
    private static _instance: ADManager;
    public static get instance(): ADManager {
        if (!this._instance) {
            this._instance = new ADManager();
        }
        return this._instance;
    }
    /**激活接口 */
    init() {
        console.log("初始化广告组件本")
        this.wxBanner.initWxBannerAd();
        this.wxCellBanner.initWxBannerAd();
        this.wxVideoAd.initWxVideo()
    }
    /**微信banner广告入接口 */
    public get wxBanner(): wxBanner {
        if (this._wxBannerMgr === undefined) {
            this._wxBannerMgr = new wxBanner();
        }
        return this._wxBannerMgr;
    }
    /**微信cell广告入接口 */
    public get wxCellBanner(): wxCellBanner {
        if (this._wxCellBanner === undefined) {
            this._wxCellBanner = new wxCellBanner();
        }
        return this._wxCellBanner;
    }
    /**微信广告视频接口 */
    public get wxVideoAd(): wxVideo {
        if (this._wxVideoAd === undefined) {
            this._wxVideoAd = new wxVideo();
        }
        return this._wxVideoAd;
    }


    /**骗点接口 */
    public get wxAdRipoff(): wxAdRipoff {
        if (this._wxAdRipoff === undefined) {
            this._wxAdRipoff = new wxAdRipoff();
        }
        return this._wxAdRipoff;
    }
    /**
     * 打开其他APP小程序
     * @param appId AppID
     * @param path 路径
     * @returns 
     */
    public async openWxAPP(appId, path, dataSource) {
        return await WXAPIMgr.navigateToMiniProgram(appId, path, dataSource)
    }
    /**关闭所有广告 */
    public closeAllBanner() {
        adModel.isFocreHiddeBanner = true
        let data = this.wxBanner.onHideBanner(true)
        ADMgr.wxCellBanner.hideCustomAd()
        ZYEventMgr.emit(ADEvent.HIDE_BOTTOM_AD)
        return data;
    }
    /**显示banner广告 */
    public showBanner(timr = 10000000000000000) {
        adModel.isFocreHiddeBanner = false;
        ADMgr.wxBanner.onShowBanner();
        ADMgr.wxBanner.onReSetTimer(true, timr);
    }
}
export const ADMgr = ADManager.instance